package com.rain.service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.rain.dto.chathistory.ChatHistoryQueryRequest;
import com.rain.entity.ChatHistory;
import com.rain.entity.User;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;

import java.time.LocalDateTime;

/**
 *  服务层。
 *
 * @author <a href="https://github.com/liyupi">程序员刘诗雨</a>
 */
public interface ChatHistoryService extends IService<ChatHistory> {

    boolean addChatHistory(Long appId,Long userId,String message,String messageType);

    boolean deleteByAppId(Long appId);

    QueryWrapper getQueryWrapper(ChatHistoryQueryRequest chatHistoryQueryRequest);

    /**
     * 分页查询某 APP 的对话记录
     *
     * @param appId
     * @param pageSize
     * @param lastCreateTime
     * @param loginUser
     * @return
     */
    Page<ChatHistory> listAppChatHistoryByPage(Long appId, User loginUser,
                                               LocalDateTime lastCreateTime,
                                               int pageSize);

    /**
     * 加载对话历史到内存
     *
     * @param appId
     * @param chatMemory
     * @param maxCount 最多加载多少条
     * @return 加载成功的条数
     */
    int loadChatHistoryToMemory(long appId, MessageWindowChatMemory chatMemory, int maxCount);
}
